package it.trio.monopoly.domain;

import it.trio.monopoly.util.Terminal;

public class Player {

	public static final int INITIAL_CASH_AMOUNT = 1500;
	String name = "";
	private Board board;
	private Square currentSquare;
	private Die d1;
	private Die d2;
	private Terminal terminal;
	private int cash;
	
	public Player(String name, Die d1, Die d2, Board board, Terminal terminal)  {
		this.d1 = d1;
		this.d2 = d2;
		this.board = board;
		this.terminal = terminal;
		this.currentSquare = board.getFirstSquare();
		this.cash = INITIAL_CASH_AMOUNT;
		this.name = name;
	}

	public Square getCurrentSquare() {
		return currentSquare;
	}

	public void setCurrentSquare(Square currentSquare) {
		this.currentSquare = currentSquare;
	}

	public String getName() {
		return name;
	}

	public void takeTurn() {
		d1.roll();
		d2.roll();
		
		currentSquare = board.getNextSquare(currentSquare, d1.getFaceValue() + d2.getFaceValue());
		
		// the two dice might be wanted to be shown together by the UI (eg. animation)
		terminal.output(d1, d2);
	}

	public Terminal getTerminal() {
		return terminal;
	}

	public void credit(int creditAmount) {
		cash  +=creditAmount;
	}

	public int getNetWorth() {
		return cash;
	}

	public void debit(int debitAmount) {
		cash = cash - debitAmount;
		
	}
}
